home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / xyos2shl.zip / O2.CMD < prev    next >
OS/2 REXX Batch file  |  1996-06-03  |  5KB  |  192 lines

  1. /****
  2.    REXX   O2.CMD [XYOS2SHL.ZIP]  R.J.Holmgren  6/3/96
  3.    Start OS/2 [DOS|WIN3x] process from XyWrite
  4.  
  5.    Non-STARTOS2 command line switches:
  6.    /E                       Turn ECHO ON during execution
  7.    /H                       Halt before exiting shell
  8.    /L:launch_process_title  optional "title" of process|object Launched
  9.    /L:"launch proc title"     ditto
  10.    /P:exit_process_title    On-the-fly "ExitProc" definition for PMSW.EXE
  11.    /P:"exit process title"    ditto
  12.    /R                       Execute as REXX script, not batch commands
  13. ****/
  14.  
  15.                               /* Load RexxUtil */
  16. if RxFuncQuery("SysLoadFuncs") then do
  17.   call RxFuncAdd "SysLoadFuncs","RexxUtil","SysLoadFuncs"
  18.   call SysLoadFuncs
  19.   end
  20.  
  21.                               /* Set|Verify filenames */
  22. BootDrive=''
  23. if length(BootDrive)=0 then call Help
  24. IniFile=BootDrive||':\OS2\MDOS\O2.INI'
  25. SwitchFile=BootDrive||':\OS2\MDOS\PMSW.EXE'
  26. currdir=directory()
  27.  
  28. linein(IniFile,1,0)           /* (Re)Set Read/Write Position */
  29. if lines(IniFile)=0 then call Help
  30.  
  31. args=linein(IniFile)          /* Read O2.INI */
  32. ucargs=translate(args)
  33. Command=linein(IniFile)
  34.  
  35. x=stream(IniFile,'C','close') /* Destroy O2.INI */
  36.  
  37.                               /* Read user input (O2 args) */
  38. hold=0; if pos('/H',ucargs)>0 then hold=1
  39.  
  40. if pos('/E',ucargs)>0 then '@echo on'
  41. else '@echo off'
  42.  
  43. rexxon=0; if pos('/R',ucargs)>0 then rexxon=1
  44.  
  45. backon=0; if pos('/B',ucargs)>0 then backon=1
  46.  
  47. exitprocon=1; if pos('/O',ucargs)>0 then exitprocon=0
  48.  
  49. ObjProc=''
  50. x=pos('/L:',ucargs)
  51. if x>0 then do
  52.   x1=pos('/L:"',ucargs)
  53.   if x=x1 then do
  54.     ObjProc=substr(args,x+4)
  55.     x=pos('"',ObjProc)
  56.     end
  57.   else do
  58.     ObjProc=substr(args,x+3)
  59.     x=pos(' ',ObjProc)
  60.     end
  61.   if x>0 then ObjProc=substr(ObjProc,1,x-1)
  62.   end
  63.  
  64. ExitProc=''
  65. x=pos('/P:',ucargs)
  66. if x>0 then do
  67.   x1=pos('/P:"',ucargs)
  68.   if x=x1 then do
  69.     ExitProc=substr(args,x+4)
  70.     x=pos('"',ExitProc)
  71.     end
  72.   else do
  73.     ExitProc=substr(args,x+3)
  74.     x=pos(' ',ExitProc)
  75.     end
  76.   if x>0 then ExitProc=substr(ExitProc,1,x-1)
  77.   end
  78.  
  79. quot=""""
  80. dr=''
  81. dirs=''
  82. dirs1=''
  83. fn=''
  84. pause=1
  85.  
  86. Command=strip(Command)        /* Strip leading+trailing spaces */
  87. TmpCmnd=Command
  88.  
  89. x=pos('CALL ',translate(TmpCmnd))  /* Get drive/dir/filename of Command */
  90. if x=1 then TmpCmnd=substr(TmpCmnd,x+5)
  91. x=pos(' ',TmpCmnd)
  92. if x>0 then TmpCmnd=substr(TmpCmnd,1,x-1)
  93. if TmpCmnd='' then call Help
  94.  
  95. object=0                      /* Is "Command" an <objectID>? 0=No 1=Yes */
  96. x=pos('<',TmpCmnd)
  97. x1=pos('>',TmpCmnd)
  98. if x=1&x1=length(TmpCmnd) then object=1
  99.  
  100. if object=0 then do           /* Set drive/dir/filename if command */
  101.   verify=stream(TmpCmnd,'C','query exists')
  102.   if Verify\='' then do
  103.     dr=filespec("drive",TmpCmnd)
  104.     dirs=filespec("path",TmpCmnd)
  105.     dirs1=dirs
  106.     if length(dirs)>1 then dirs1=left(dirs,length(dirs)-1)
  107.     fn=filespec("name",TmpCmnd)
  108.     end
  109.   end
  110.  
  111. if object=1 then do           /* Open object */
  112.   rc=SysSetObjectData(TmpCmnd,"OPEN=DEFAULT")  /* Open object */
  113.  
  114.   if rc=1 then do
  115.     if ObjProc=''&backon=0&exitprocon=0 then do
  116.       call SysSetObjectData TmpCmnd,"OPEN=DEFAULT" /* Try(!) to get Focus*/
  117.       call SysFileDelete IniFile
  118.       exit
  119.       end
  120.     end
  121.   else do
  122.     say "Open failed:  "||TmpCmnd              /* If OPEN failed */
  123.     say "Hit key to quit..."
  124.     call SysGetKey 'noecho'
  125.     pause=2
  126.     end
  127.   end
  128.  
  129. if object=0 then do           /* Execute command */
  130.   if dr\='' then dr
  131.   if dirs1\='' then 'cd' dirs1
  132.   rc=0
  133.   if rexxon=1&fn\=RUNCMD.CMD then do
  134.     interpret Command         /* If Rexx */
  135.     end
  136.   else Command                /* Otherwise */
  137.   if rc>1&rc\=255 then do
  138.     say
  139.     say '    Exit code: '||fn
  140.     call charout ,'    >>RC='||rc||'<<    Hit any key to continue . . . '
  141.     call SysGetKey 'noecho'
  142.     pause=2
  143.     say
  144.     say
  145.     end
  146.   if fn=RUNCMD.CMD then call SysFileDelete TmpCmnd
  147.   end
  148.  
  149. if ObjProc\=''&backon=0 then do
  150.   SwitchFile' *'ObjProc'*'    /*Get Focus*/
  151.   call SysSleep 1
  152.   SwitchFile' *'ObjProc'*'    /*Some PMs need extra loadtime */
  153.     say 'Focusing on "*'ObjProc'*"; Ctrl-C aborts...'
  154.     do forever
  155.       call SysSleep 1
  156.       SwitchFile' *'ObjProc'* /R'   /* Is app "focus-able"? */
  157.       if rc\=1 then leave
  158.       end
  159.   end
  160.  
  161. call callit
  162. call SysFileDelete IniFile
  163. exit
  164.  
  165. return
  166.  
  167. HELP:
  168.   say
  169.   say 'O2.CMD [XYOS2SHL.ZIP]  R.J.Holmgren  6/3/96'
  170.   say 'Execute|Open OS/2 commands|objects from XyWrite Word Processor'
  171.   say
  172.   say 'Run INSTALL.CMD to install Xy-OS/2 Shell.'
  173.   say 'O2.CMD is initiated by XPL (U2) program "O2.PM";'
  174.   say '  O2.CMD is !NOT! run directly from the OS/2 command line.'
  175.   exit
  176. RETURN
  177.  
  178. CALLIT:
  179. x1=pos('/C',ucargs)
  180. if hold=1&pause=1&object=0 then call HoldOn         /* Don't pause twice */
  181. if ExitProc\='' then 'call '||BootDrive||':\OS2\MDOS\SW.CMD '||ExitProc
  182. if x1=0&object=0 then call directory currdir
  183. RETURN
  184.  
  185. HOLDON:
  186.   call charout ,'-- Hit any key to SWitch to 'quot||ExitProc||quot
  187.   if x1>0 then call charout ,' (and kill this process)'
  188.   call charout ,' --'
  189.   call SysGetKey 'noecho'
  190. RETURN
  191.  
  192.